USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[BillsDetails-Insert]    Script Date: [[20120714223926]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223926]]
-- Description:	Insert record into table [dbo].[BillsDetails]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[BillsDetails-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[BillsDetails-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[BillsDetails-Insert]
	/*@BillDetail_RowNumber int =Null OUTPUT , 
	@BillDetail_ID uniqueidentifier =Null  , 
	@Bill_ID uniqueidentifier =Null  , 
	@Product_ID uniqueidentifier =Null  , 
	@Offer_ID uniqueidentifier =Null  , 
	@Store_ID uniqueidentifier =Null  , 
	@Quantity float =Null  , 
	@MeasureUnit_ID uniqueidentifier =Null  , 
	@Price float =Null  , 
	@IsAdding tinyint =1*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[BillsDetails](/*[BillDetail_ID], [Bill_ID], [Product_ID], [Offer_ID], [Store_ID], [Quantity], [MeasureUnit_ID], [Price], [IsAdding]*/)
	VALUES     (/*@BillDetail_ID, @Bill_ID, @Product_ID, @Offer_ID, @Store_ID, @Quantity, @MeasureUnit_ID, @Price, @IsAdding*/)

	/*SELECT @BillDetail_RowNumber = [BillDetail_RowNumber]
    FROM [dbo].[BillsDetails]
    WHERE  ( [BillDetail_ID] =@BillDetail_ID )
	AND  ( [Bill_ID] =@Bill_ID )
	AND  ( [Product_ID] =@Product_ID )
	AND  ( [Offer_ID] =@Offer_ID )
	AND  ( [Store_ID] =@Store_ID )
	AND  ( [Quantity] =@Quantity )
	AND  ( [MeasureUnit_ID] =@MeasureUnit_ID )
	AND  ( [Price] =@Price )
	AND  ( [IsAdding] =@IsAdding )*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[BillsDetails-update]    Script Date: [[20120714223926]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223926]]
-- Description:	Update record in table [dbo].[BillsDetails]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[BillsDetails-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[BillsDetails-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[BillsDetails-update]
	/*@BillDetail_RowNumber int =Null OUTPUT , 
	@BillDetail_ID uniqueidentifier =Null  , 
	@Bill_ID uniqueidentifier =Null  , 
	@Product_ID uniqueidentifier =Null  , 
	@Offer_ID uniqueidentifier =Null  , 
	@Store_ID uniqueidentifier =Null  , 
	@Quantity float =Null  , 
	@MeasureUnit_ID uniqueidentifier =Null  , 
	@Price float =Null  , 
	@IsAdding tinyint =1*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[BillsDetails] SET 
		/*[BillDetail_ID] =@BillDetail_ID, 
		[Bill_ID] =@Bill_ID, 
		[Product_ID] =@Product_ID, 
		[Offer_ID] =@Offer_ID, 
		[Store_ID] =@Store_ID, 
		[Quantity] =@Quantity, 
		[MeasureUnit_ID] =@MeasureUnit_ID, 
		[Price] =@Price, 
		[IsAdding] =@IsAdding*/
		/*WHERE ([BillDetail_ID] = @BillDetail_ID)*/
	/**/

	/*SELECT @BillDetail_RowNumber = [BillDetail_RowNumber]
    FROM [dbo].[BillsDetails]
	WHERE ([BillDetail_ID] = @BillDetail_ID)*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[BillsDetails-Insert-Update]    Script Date: [[20120714223926]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223926]]
-- Description:	Insert OR Update record into table [dbo].[BillsDetails]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[BillsDetails-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[BillsDetails-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[BillsDetails-Insert-Update]
	/*@BillDetail_RowNumber int =Null OUTPUT , 
	@BillDetail_ID uniqueidentifier =Null  , 
	@Bill_ID uniqueidentifier =Null  , 
	@Product_ID uniqueidentifier =Null  , 
	@Offer_ID uniqueidentifier =Null  , 
	@Store_ID uniqueidentifier =Null  , 
	@Quantity float =Null  , 
	@MeasureUnit_ID uniqueidentifier =Null  , 
	@Price float =Null  , 
	@IsAdding tinyint =1  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[BillsDetails] 
					/*WHERE ([BillDetail_ID] = @BillDetail_ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[BillsDetails](/*[BillDetail_ID], [Bill_ID], [Product_ID], [Offer_ID], [Store_ID], [Quantity], [MeasureUnit_ID], [Price], [IsAdding]*/)
		VALUES     (/*@BillDetail_ID, @Bill_ID, @Product_ID, @Offer_ID, @Store_ID, @Quantity, @MeasureUnit_ID, @Price, @IsAdding*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[BillsDetails] SET 
			/*[BillDetail_ID] =@BillDetail_ID, 
			[Bill_ID] =@Bill_ID, 
			[Product_ID] =@Product_ID, 
			[Offer_ID] =@Offer_ID, 
			[Store_ID] =@Store_ID, 
			[Quantity] =@Quantity, 
			[MeasureUnit_ID] =@MeasureUnit_ID, 
			[Price] =@Price, 
			[IsAdding] =@IsAdding*/
			/*WHERE ([BillDetail_ID] = @BillDetail_ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @BillDetail_RowNumber = [BillDetail_RowNumber]
    FROM [dbo].[BillsDetails]
	WHERE ([BillDetail_ID] = @BillDetail_ID)*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[BillsDetails-Delete]    Script Date: [[20120714223926]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223926]]
-- Description:	delete records from table [dbo].[BillsDetails] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[BillsDetails-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[BillsDetails-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[BillsDetails-Delete]
	/*@BillDetail_RowNumber int =null  , 
	@BillDetail_ID uniqueidentifier =null  , 
	@Bill_ID uniqueidentifier =null  , 
	@Product_ID uniqueidentifier =null  , 
	@Offer_ID uniqueidentifier =null  , 
	@Store_ID uniqueidentifier =null  , 
	@Quantity float =null  , 
	@MeasureUnit_ID uniqueidentifier =null  , 
	@Price float =null  , 
	@IsAdding tinyint =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[BillsDetails]
	WHERE /*( [BillDetail_RowNumber] = ISNULL(@BillDetail_RowNumber, [BillDetail_RowNumber]) )
	AND ( [BillDetail_ID] = ISNULL(@BillDetail_ID, [BillDetail_ID]) )
	AND ( [Bill_ID] = ISNULL(@Bill_ID, [Bill_ID]) )
	AND ( [Product_ID] = ISNULL(@Product_ID, [Product_ID]) )
	AND ( [Offer_ID] = ISNULL(@Offer_ID, [Offer_ID]) )
	AND ( [Store_ID] = ISNULL(@Store_ID, [Store_ID]) )
	AND ( [Quantity] = ISNULL(@Quantity, [Quantity]) )
	AND ( [MeasureUnit_ID] = ISNULL(@MeasureUnit_ID, [MeasureUnit_ID]) )
	AND ( [Price] = ISNULL(@Price, [Price]) )
	AND ( [IsAdding] = ISNULL(@IsAdding, [IsAdding]) )*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[BillsDetails-Select]    Script Date: [[20120714223926]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223926]]
-- Description:	select records from table [dbo].[BillsDetails] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[BillsDetails-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[BillsDetails-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[BillsDetails-Select]
	/*@BillDetail_RowNumber int =null  , 
	@BillDetail_ID uniqueidentifier =null  , 
	@Bill_ID uniqueidentifier =null  , 
	@Product_ID uniqueidentifier =null  , 
	@Offer_ID uniqueidentifier =null  , 
	@Store_ID uniqueidentifier =null  , 
	@Quantity float =null  , 
	@MeasureUnit_ID uniqueidentifier =null  , 
	@Price float =null  , 
	@IsAdding tinyint =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[BillsDetails]
	WHERE /*( [BillDetail_RowNumber] = ISNULL(@BillDetail_RowNumber, [BillDetail_RowNumber]) )
	AND ( [BillDetail_ID] = ISNULL(@BillDetail_ID, [BillDetail_ID]) )
	AND ( [Bill_ID] = ISNULL(@Bill_ID, [Bill_ID]) )
	AND ( [Product_ID] = ISNULL(@Product_ID, [Product_ID]) )
	AND ( [Offer_ID] = ISNULL(@Offer_ID, [Offer_ID]) )
	AND ( [Store_ID] = ISNULL(@Store_ID, [Store_ID]) )
	AND ( [Quantity] = ISNULL(@Quantity, [Quantity]) )
	AND ( [MeasureUnit_ID] = ISNULL(@MeasureUnit_ID, [MeasureUnit_ID]) )
	AND ( [Price] = ISNULL(@Price, [Price]) )
	AND ( [IsAdding] = ISNULL(@IsAdding, [IsAdding]) )*/
END
GO
-- =============================================
